package com.hp.mapper;

import com.hp.entity.Apply;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ApplyMapper {
    /**
     *  查询所有人的信息
     * @return
     * @select:用于查询的注解开发
     * @Results:可以重复使用类似于sql片段
     */
    @Select("SELECT * FROM apply_info")
    @Results(id="ApplyMap",
            value={
                    @Result(id=true,column="id",property="id"),
                    @Result(column="name",property="name"),
                    @Result(column="age",property="age"),
                    @Result(column="aclass",property="aclass"),
                    @Result(column="game",property="game")
            })
    List<Apply> getUsers();

    /**
     *   根据id查询信息
     * @param id
     * @return
     */
    @Select("SELECT * FROM apply_info WHERE id=#{id}")
    @ResultMap("ApplyMap")
    List<Apply> getById(int id);

    /**
     *  根据名字模糊，并且根据运动项目查询 (使用动态sql)
     * @param
     * @return
     */
    @Select("SELECT * FROM apply_info WHERE name like CONCAT('%',CONCAT(#{name},'%'));")
    @ResultMap("ApplyMap")
    List<Apply> getByNameGame(String name);

    /**
     *  添加信息
     * @param apply
     */
    @Insert("INSERT INTO apply_info (NAME,age,aclass,game)VALUES(#{name},#{age},#{aclass},#{game})")
    void addApply(Apply apply);

    /**
     *  根据id修改人员信息
     * @param apply
     * @return
     */
    @Update("UPDATE apply_info SET NAME=#{name},age=#{age},aclass=#{aclass},game=#{game} WHERE id=#{id}")
    int updateApply(Apply apply);

    /**
     *  根据id删除人员信息
     * @param id
     * @return
     */
    @Delete("DELETE FROM apply_info WHERE id=#{id}")
    int delApply(int id);
}
